home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- #define VAT 0.175
-
- main()
- {
- float cost; // Create a floating-point variable called 'cost'
-
- printf("The VAT rate is %f percent\n", VAT*100);
- /*----------------------------------------------------------+
- | Note how we use %f to handle a floating point number. The |
- | 'VAT' inside the string is not converted because the |
- | contents of strings are taken literally - unless there's |
- | a special modifier code like \ or %. |
- | The second, naked 'VAT', however, is expanded to 0.175. |
- +----------------------------------------------------------*/
- cost=1.50; // Assign the value 1.5 to cost
- printf("The cost is £%f\n", cost); // Print it
- cost=cost+(cost*VAT); //Add VAT to it
- printf("The cost, including VAT, is £%.2f\n", cost); //Print again
- /*-------------------------------------------------------+
- | See how .2 has been inserted between % and f. This |
- | truncates the number to two decimal places. Truncating |
- | is not the same as rounding! |
- +-------------------------------------------------------*/
-
- }
-
- // Press Alt+F5 to see the output screen
-
-